from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
from django.views.generic import *
from django.views.generic import DetailView,ListView
from resume.models import resumep,JOb
from django.core.paginator import Paginator
from django.db.models import Q


#添加简历信息保存到数据库
def insert(request):
    if request.method == "POST":
        re = resumep()
        re.username = request.POST.get("point4")
        re.sex = request.POST.get("sex")
        re.address = request.POST.get("address")
        re.phone = request.POST.get("point8")
        re.work = request.POST.get("experience")
        re.educational = request.POST.get("education")
        re.job = request.POST.get("expected_work")
        re.save()
    return render(request, 'jianli.html')

#列表页和分页
def job_list(request):
    j_list = JOb.objects.all()
    paginator = Paginator(j_list,5)  # 按每一条3条数据显示
    page = request.GET.get('page')  # 获取页码数
    j = paginator.get_page(page)
    context = {'j': j}
    return render(request, 'list.html', context)

#查询功能
def search(request):
    q = request.POST.get('q')
    error_msg = ''
    if not q:
        error_msg = "请输入关键词"
        return render(request, 'search.html', {'error_msg': error_msg})
    r_list=JOb.objects.filter(job__icontains=q)
    return render(request,'search.html',{'error_msg': error_msg,'r_list': r_list,'q':q})

#详情页
def detail(request, pk):
        j = JOb.objects.get(pk=pk)
        return render(request, "detail.html", context={"j": j})
#可视化
from django.db.models import Count,F
from django.shortcuts import render
def pie(request):
    result = JOb.objects.values("job").annotate(value=Count("id"),name=F("job"))
    result = list(result)
    return render(request,"echart.html",{"name_data":result})

